package com.zdy.im.user.controller;



import java.util.List;

import com.sixeco.framework.common.api.ApiDoc;
import com.sixeco.framework.common.data.BasePage;
import com.sixeco.framework.core.db.IterableConverter;
import com.sixeco.framework.http.data.vo.HttpRequestByIdVo;
import com.sixeco.framework.http.data.vo.ResponseResultList;
import com.sixeco.framework.http.handler.OutputResponse;
import com.zdy.im.user.UrlCommand;
import com.zdy.im.user.vo.request.ChatQueryRequestVo;
import com.zdy.im.user.vo.request.ImChatMessageHistoryRequestVo;
import com.zdy.im.user.dto.request.ImChatMessageRequestDto;
import com.zdy.im.user.dto.response.ImChatMessageResponseDto;
import com.zdy.im.user.facade.ImChatMessageFacade;
import com.zdy.im.user.service.ImChatMessageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.beans.factory.annotation.Autowired;


import com.zdy.im.user.vo.response.ImChatMessageShowResponseVo;

/**
 * @Title: ImChatMessageController.java
 * @Author 作者 : zdy
 * @CreateDate 创建时间: 2021-02-30
 * @version V1.0
 *  <pre>
 * 修改记录
 *    修改后版本:     修改人：  修改日期:     修改内容:
 * </pre>
 * @Description: TODO(说明) 对象缓存统一模板实现类;
 */
@ApiDoc(
        module = "模块", isApp = true
)
@Controller
public class ImChatMessageController {

    @Autowired
    private ImChatMessageFacade imChatMessageFacade;

    @Autowired
    private ImChatMessageService imChatMessageService;



    /**
    * @Title: test测试生成类分页信息
    * @Description:testRequestVo @{Link TestRequestVo}
    * @param
    * @return
    * @throw
    * @author suven
    * @date 2019-07-19 13:16:48
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    @ApiDoc(
            value = "分页获取指定用户间的聊天记录信息",
            request = ImChatMessageHistoryRequestVo.class,
            response = ImChatMessageShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imChatMessage_pageList, method = RequestMethod.GET)
    public void list(OutputResponse out, ImChatMessageHistoryRequestVo imChatMessageQueryRequestVo){
            ImChatMessageRequestDto imChatMessageRequestDto = ImChatMessageRequestDto.build( ).clone(imChatMessageQueryRequestVo);
        ResponseResultList list =  ResponseResultList.build();
        BasePage page =  BasePage.build().toPageSize(imChatMessageQueryRequestVo.getPageSize()).toPageNo(imChatMessageQueryRequestVo.getPageNo());
        page.toParamObject(imChatMessageRequestDto );
        ResponseResultList<ImChatMessageResponseDto> resultList = imChatMessageService.getImChatMessageByUserIdToIdPage(page);

        if(null == resultList || resultList.getList().isEmpty() ){
            out.write(list);
            return;
        }
        List<ImChatMessageShowResponseVo> listVo = IterableConverter.convertList(resultList.getList(),ImChatMessageShowResponseVo.class);

        list =  ResponseResultList.build().toList(listVo)
                .toIsNextPage(resultList.getIsNextPage());
        out.write(list);
    }


    @ApiDoc(
            value = "获取最新消息列表",
            request = ChatQueryRequestVo.class,
            response = ImChatMessageShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_new_imChatMessage, method = RequestMethod.GET)
    public void messageList(OutputResponse out, ChatQueryRequestVo chatQueryRequestVo){

        List<ImChatMessageShowResponseVo> listVo = imChatMessageFacade.getUserChatMessageList(chatQueryRequestVo.getUserId());
        out.write(listVo);
    }





    /**
    * @Title: 查看test测试生成类信息
    * @Description:testRequestVo @{Link TestRequestVo}
    * @param
    * @return
    * @throw
    * @author suven
    * @date 2019-07-19 13:16:48
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    @ApiDoc(
            value = "查看信息",
            request = HttpRequestByIdVo.class,
            response = ImChatMessageShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imChatMessage_info ,method = RequestMethod.GET)
    public void detail(OutputResponse out, HttpRequestByIdVo idRequestVo){

            ImChatMessageResponseDto imChatMessageResponseDto = imChatMessageService.getImChatMessageById(idRequestVo.getId());
            ImChatMessageShowResponseVo vo =  ImChatMessageShowResponseVo.build().clone(imChatMessageResponseDto);
        out.write(vo);
    }

}
